package com.drinks.yiniang.adapter.user.points;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;

import com.chad.library.adapter.base.BaseViewHolder;
import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.base.BaseQuickRCVAdapter;
import com.drinks.yiniang.entity.user.points.CouponJson;
import com.hansen.library.utils.ScreenSizeUtils;
import com.hansen.library.utils.StringUtils;

import java.util.List;

/**
 * 积分兑换列表adapter
 * @author han
 * @date 2019/8/30
 */
public class CouponAdapter extends BaseQuickRCVAdapter<CouponJson.CouponList, BaseViewHolder> {

    private SpannableStringBuilder mBuilder;

    private String mCouponType;

    private int sp18;

    public CouponAdapter(Context mContext, @Nullable List<CouponJson.CouponList> data) {
        super(R.layout.item_coupon, data);

        mBuilder = new SpannableStringBuilder();

        sp18 = ScreenSizeUtils.sp2Px(mContext, 18);
    }

    @Override
    protected void convert(BaseViewHolder helper, CouponJson.CouponList item) {
        if(!StringUtils.isPositiveIntNumber(item.getStores_id())) {//通用
            //tag
            helper.setText(R.id.tv_coupon_tag, mContext.getString(R.string.text_coupon));
            //使用平台
            helper.setText(R.id.tv_coupon_use_place, mContext.getString(R.string.text_coupon_use_by_all));
        } else {//门店
            //tag
            helper.setText(R.id.tv_coupon_tag, mContext.getString(R.string.text_shop_coupon_simple));
            //使用平台
            helper.setText(R.id.tv_coupon_use_place, String.format(mContext.getString(R.string.text_only_one_store_use_format), StringUtils.getNullEmptyConvert__(item.getStores_name())));
        }

        //金额
        mBuilder.clearSpans();
        mBuilder.clear();
        mBuilder.append("¥");
        mBuilder.append(" ");
        mBuilder.append(StringUtils.getNullEmptyConvert__(item.getAmount()));
        mBuilder.setSpan(new AbsoluteSizeSpan(sp18), 0, 2, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        helper.setText(R.id.tv_coupon_value, mBuilder);
        //使用限制
        helper.setText(R.id.tv_coupon_require, String.format(mContext.getString(R.string.text_use_limit_money_format), StringUtils.getNullEmptyConvert__(item.getLimit_amount())));
        //期限
        mBuilder.clearSpans();
        mBuilder.clear();
        mBuilder.append(StringUtils.getNullEmptyConvert__(item.getValid_start_time()));
        mBuilder.append("—");
        mBuilder.append(StringUtils.getNullEmptyConvert__(item.getValid_end_time()));
        helper.setText(R.id.tv_coupon_use_time, mBuilder);
    }
}
